package com.hen.web.henweb.exception;

import com.hen.web.henweb.common.R;
import com.hen.web.henweb.model.enumeration.StatusMsgEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 狠穿
 * @version 1.0.0
 * @date 2023/3/17
 * @function 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public R globalException(HttpServletResponse response,Exception e){
        log.info(e.getMessage());
        int status = response.getStatus();
        if( status == StatusMsgEnum.SUCCESS.getCode()){
            return R.succ(StatusMsgEnum.SUCCESS.getMsg());
        }
        return R.fail(e.getMessage());
    }
}
